import rarfile
import os
import sys

def unrar_file(rar_file_name,destination_path):
    archive = rarfile.RarFile(rar_file_name,mode='r')
    for file in archive.namelist():
        print(file)
        archive.extract(file, destination_path, 'www.jinshuyuan.net')

def rarfile_name(file_dir):
    # 读取文件夹下面的文件名.rar
    X=[]
    for root, dirs, files in os.walk(file_dir):
        for file in files:
            if os.path.splitext(file)[1] == '.rar':    # 读取带rar 文件
                X.append(os.path.join(root, file))
                #print(X)
    return X


def main():
    inputPath = "/Volumes/disk/ctp_data"
    outPath = "/Volumes/disk/ctp_data_unrar"
    bn = rarfile_name(inputPath)
    for file in bn:
        unrar_file(file, outPath)


if __name__ == "__main__":
    main()
    print("done")
